package view;

import dao.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/logout")
public class logout extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session=req.getSession(false);
        //检查用户有没有直接登录
        if(session==null){
            String html="用户不存在";
            resp.getWriter().write(html);
        }
        //不管有没有直接删除
        session.removeAttribute("user");
        //3.重定向
        resp.sendRedirect("logout.html");
        resp.setContentType("application/javascript");
        String str= "alert(\"用户已退出\")";
        resp.getWriter().write(str);
    }
}
